﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestGame {
    class ParticleSystem {
        private static List<Particle> particles = new List<Particle>();

        public static void AddStandardStarParticles(Vector2 pos) {
            float dist = 50.0f;
            TimeSpan oneSec = TimeSpan.FromSeconds(1.0);

            ParticleSystem.AddToList(new Particle(pos, new LinearPath(dist, dist, oneSec)));
            ParticleSystem.AddToList(new Particle(pos, new LinearPath(dist, -dist, oneSec)));
            ParticleSystem.AddToList(new Particle(pos, new LinearPath(-dist, dist, oneSec)));
            ParticleSystem.AddToList(new Particle(pos, new LinearPath(-dist, -dist, oneSec)));
        }

        public static void AddToList(Particle newParticle) {
            particles.Add(newParticle);
        }

        public static void Update(GameTime gameTime) {
            for (int i = 0; i < particles.Count; i++) {
                Particle particle = particles[i];

                if (particle.HasFinished()) {
                    particles.RemoveAt(i--);
                }
                else {
                    particle.Update(gameTime);
                }
            }
        }

        public static void LoadContent(ContentManager content) {
            Particle.LoadContent(content);
        }

        public static void Draw(SpriteBatch spriteBatch, ContentManager content) {
            foreach (Particle particle in particles) {
                particle.Draw(spriteBatch, content);
            }
        }
    }
}
